
package Loader;

import java.io.File;
import java.util.LinkedList;
import java.util.Scanner;

public class LoaderWine implements LoaderInterface {

    public LinkedList<Pair> load(String fileName) {

        LinkedList<Pair> data = new LinkedList<Pair>();
        File fFile = new File(fileName);
        Scanner scanner = null;

        try {

            scanner = new Scanner(fFile);

            while ( scanner.hasNextLine() ) {

                Scanner scannerL = new Scanner(scanner.nextLine());
                scannerL.useDelimiter(",");

                 if ( scannerL.hasNext() ) {

                    float[] features = new float[13];
                    int noClass = scannerL.nextInt();

                    for(int i=0;i<13;++i)
                        features[i] = Float.parseFloat(scannerL.next());
                    
                    data.add(new Pair(noClass, features));

                 }

            }

        } catch(Exception e) {

            System.out.println(e);
            return null;

        }

        scanner.close();
        return data;
        
    }

}
